package com.cfc.mongodb.vo;

import cn.hutool.core.util.PageUtil;
import com.cfc.mongodb.entity.PageParam;
import lombok.Data;

import java.util.Collections;
import java.util.List;

//@ApiModel("分页返回信息")
@Data
public class PageResult<T> {

    //@ApiModelProperty(value = "数据")
    private List<T> records;

    //@ApiModelProperty(value = "当前页",required = true)
    private long current;

    //@ApiModelProperty(value = "每页数量",required = true)
    private long limit;

    //@ApiModelProperty(value = "总条数",required = true)
    private long total;

    //@ApiModelProperty(value = "总页数")
    private long totalPage;

    public PageResult() {
        this.records = Collections.emptyList();
        this.current = 1L;
        this.limit = 10L;
        this.total = 0L;
        this.totalPage = 0L;
    }

    public PageResult(long total, long totalPages, List<T> records) {
        this.records = records;
        this.total = total;
        this.totalPage =totalPages;
    }

    public PageResult(long current, long limit, long total, long totalPages, List<T> records) {
        this.records = records;
        this.current = current;
        this.limit = limit;
        this.total = total;
        this.totalPage = PageUtil.totalPage((int)this.total, (int)this.limit);
    }

    public PageResult(PageParam pageParam, long total, List<T> records) {
        this.records = records;
        this.current = pageParam.getCurrent();
        this.limit = pageParam.getLimit();
        this.total = total;
        this.totalPage = PageUtil.totalPage((int)this.total, (int)this.limit);
    }
}